package cn.akwangl.controller;

import cn.akwangl.common.PagedGridResult;
import cn.akwangl.common.Result;
import cn.akwangl.pojo.VehicleTrack;
import cn.akwangl.pojo.bo.VehicleTrackQuery;
import cn.akwangl.service.IVehicleTrackService;
import cn.akwangl.service.async.VehicleTrackServiceAsync;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 车辆迹信息 前端控制器
 * </p>
 *
 * @author 阿坤同学
 * @since 2022-07-08
 */
@Controller
@RequestMapping("/vehicleTrack")
public class VehicleTrackController {

    private IVehicleTrackService vehicleTrackService;

    private VehicleTrackServiceAsync vehicleTrackServiceAsync;

    @Autowired
    public void setVehicleTrackService(IVehicleTrackService vehicleTrackService) {
        this.vehicleTrackService = vehicleTrackService;
    }

    @Autowired
    @Lazy
    public void setVehicleTrackServiceAsync(VehicleTrackServiceAsync vehicleTrackServiceAsync) {
        this.vehicleTrackServiceAsync = vehicleTrackServiceAsync;
    }

    @PostMapping("/list")
    @ResponseBody
    public Result<PagedGridResult> list(@RequestBody VehicleTrackQuery query) {
        Page<VehicleTrack> page = vehicleTrackService.list(query);
        PagedGridResult pagedGridResult = PagedGridResult.createPagedGridResult(page);
        return Result.success(pagedGridResult);
    }

    @PostMapping("/asyncList")
    @ResponseBody
    public Result<PagedGridResult> asyncList(@RequestBody VehicleTrackQuery query) {
        Page<VehicleTrack> page = vehicleTrackServiceAsync.list(query);
        PagedGridResult pagedGridResult = PagedGridResult.createPagedGridResult(page);
        return Result.success(pagedGridResult);
    }

    @RequestMapping("/excelExport")
    public String excelExport() {
        return "excelExport";
    }

    @RequestMapping("/csvExport")
    public String csvExport() {
        return "csvExport";
    }
}
